
import dzmodel, dzentity, dzutil

class Product(dzentity.Entity):
    def __init__(self,rec=None,table=None):
        dzentity.Entity.__init__(self,rec)
        if not rec:
            self.NAME      = ''
            self.VERSION   = '0.1'
            self.TITLE     = ''
            self.ICONNAME  = 'blank_document'
            self.DESCR     = ''
            self.SUBJECTID = 0
            self.STATUS    = 'D'
            self.VISIBLE   = 1
            self.SYSTEM    = 0
            self.POSITION  = 5
            self.NEWDATE   = dzutil.today

    def valid_product(self):
        problems = []
        if len(self.NAME)<2:
            problems.append('Name too short')

        for problem in problems:
            dzutil.warning(problem)

        return len(problems)==0

    def update(self,keywords):
        for key in self.keys():
            if key in keywords:
                self.__dict__[key] = keywords[key]

class Products(dzmodel.Table):
    def __init__(self):
        dzmodel.table_prefix = 'dz_'
        dzmodel.Table.__init__(self,Product)
        self.table_key = 'PRODUCTID'


